<template>
 <el-dialog title="导出" :close-on-click-modal="false"  :visible.sync="show" class="dialog_del" :before-close="cancle">
    <p>请选择导出的选项</p>
      <el-radio v-model="exportWay" label="1">勾选项</el-radio>
      <el-radio v-model="exportWay" label="0">当前页</el-radio>
      <el-radio v-model="exportWay" label="2">全部查询结果</el-radio>

    <span slot="footer" class="dialog-footer">
      <el-button type="search" @click="submitForm">导出</el-button>
      <el-button @click="cancle">取消</el-button>
    </span>
  </el-dialog>
 
</template>

<script>
import { articleManageExport } from '@/api/article/article_manage.js'

import { setSearchParams } from '@/utils/index.js'

export default {
  props: {
    show: Boolean,
    closeDialog:Function,
    idList: Array
  },
  data() {
    return {
      exportWay: "1"
    }
  },
  methods: {
    cancle() {
      this.$emit('closeDialog')
      this.exportWay = "1"
    },
    submitForm(){
      let params = {}
      if(this.exportWay == 0){// 当前页
      
        params.ids = JSON.stringify(this.$parent.curIdList) 
      } else if(this.exportWay == 1){ // 勾选项
    
        let curList = this.$parent.curList
        if(curList.length == 0){
          this.$message.error({message: '导出条数不能为0条'})
          return;
        }else{
          params.ids = JSON.stringify(curList)
        }
      } else if(this.exportWay == 2) { // 全部查询结果
        params = setSearchParams(this.$parent.searchForm, this.$parent.pageSize, this.$parent.page)
        params.ids = []
      }
      this.exportForm(params)
    },
    exportForm(params){
      articleManageExport(params).then(res=>{
        if(res.state == 1){
          window.open(res.data)
          this.cancle()
        }
      })
    }
  }
}
</script>

<style lang="scss">
.dialog_del{
  .el-radio{
    color: #666666;
    margin-top: 19px;
  }
  .el-radio__inner{
    width: 16px;
    height: 16px;
  }
}

</style>